package com.py.wemedia.controller.v1;

import com.py.model.common.dtos.ResponseResult;
import com.py.model.wemedia.dtos.WmNewsDto;
import com.py.model.wemedia.dtos.WmNewsPageReqDto;
import com.py.wemedia.service.WmNewsService;
import com.py.wemedia.service.impl.WmTaskServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2022/11/10 10:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService newsService;

    @Autowired
    private WmTaskServiceImpl service;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto reqDto){

        return newsService.list(reqDto);
    }

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto newsDto) {

        return newsService.submit(newsDto);
    }

    /**
     * 文章上下架
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        return newsService.downOrUp(wmNewsDto);
    }


    /**
     * 草稿文章回显
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult one(@PathVariable int id){
        return newsService.echo(id);
    }


    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable int id){
        return newsService.deleteNews(id);
    }


    /**
     * 延迟任务拉取执行测试
     * @return
     */
    @GetMapping("/exec")
    public String test(){
        service.delayTaskExec();
        return "OK";
    }

}